package com.rxmvp.rxjavademo.RxRetrofit.exception;

import android.support.annotation.IntDef;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Created by Administrator on 2017/1/12.
 */

public class CodeException extends Exception{

    public static final int DATA_NULL_ERROR = 0x01;
    public static final int CODE_ERROR = 0x02;


    @IntDef({DATA_NULL_ERROR, CODE_ERROR})
    @Retention(RetentionPolicy.SOURCE)
    public @interface CodeEp{}


    public CodeException(@CodeEp int errCode){
        this.errCode = errCode;
    }

    private @CodeEp int errCode;
    private String errMsg;

    @CodeEp
    public int getErrCode() {
        return errCode;
    }

    public void setErrCode(@CodeEp int errCode) {
        this.errCode = errCode;
    }

    public String getErrMsg() {
        switch (errCode){
            case DATA_NULL_ERROR:
                errMsg = "服务器无响应";
                break;
            case CODE_ERROR:
                errMsg = "服务器请求错误";
                break;
        }
        return errMsg;
    }

//    public void setErrMsg(String errMsg) {
//        this.errMsg = errMsg;
//    }
}
